package com.shf.lease.web.admin.controller.apartment;

import com.shf.lease.result.Result;
import com.shf.lease.web.admin.service.FileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 叶枫
 * @date 2024/7/5.
 */

@RestController
@Tag(name = "文件管理")
@RequestMapping("/admin/file")
public class FileController {

    @Resource
    private FileService fileService;

    @Operation(summary = "上传文件")
    @RequestMapping("/upload")
    public Result<?> uploadFile(@RequestParam MultipartFile file) {

        try {
            String url = fileService.upload(file);
            return Result.ok(url);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail();
        }
    }
}
